#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int t,n,a[1000005],b;

int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--){
        cin>>n;
        int ans=0,mx=0;
        memset(a,0,sizeof(a));
        for(int i=1;i<=n;i++){
            scanf("%d",&b);
            a[b]++;
            mx=max(mx,b);
        }
        for(int i=1;i<=mx;i++){
            if(a[i]>1)ans+=i*a[i]/2;
        }
        cout<<ans<<endl;
    }
    return 0;
}
